package com.yzw.phonestoreservice.controller;


import com.yzw.phonecommen.common.R;
import com.yzw.phonestoreservice.annotation.UnInterception;
import com.yzw.phonestoreservice.pojo.PhoneInfo;
import com.yzw.phonestoreservice.service.PhoneInfoService;
import com.yzw.phonestoreservice.vo.PhoneinfoVo;
import com.yzw.phonestoreservice.vo.SkuDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: phonestoresys
 * @BelongsPackage: com.yzw.phonestoreservice.controller
 * @Author: yanhongwei
 * @CreateTime: 2022-11-02  17:39
 * @Description: TODO
 * @Version: 1.0
 */
@RequestMapping("/phone/phoneinfo")
@RestController
public class PhoneinfoController {

    @Autowired
    private PhoneInfoService phoneInfoService;

    @PostMapping("/phoneinfoList")
    public R userList(@RequestParam Map<String,Object> parameters){
        return phoneInfoService.phoneinfoList(parameters);
    }

    @PostMapping("/phoneinfoDel")
    public R phoneinfoDel(@RequestBody Integer[] ids){
        return phoneInfoService.phoneinfoDel(ids);
    }


    @GetMapping("/phoneinfoById")
    public R phoneinfoById(Integer id){
        return phoneInfoService.phoneinfoById(id);
    }

    @PostMapping("/phoneinfoAdd")
    public R phoneinfoAdd(@RequestBody PhoneInfo phoneInfo){
        return phoneInfoService.phoneinfoAdd(phoneInfo);
    }

    @PostMapping("/phoneinfoUpdate")
    public R phoneinfoUpdate(@RequestBody PhoneInfo phoneInfo){
        return phoneInfoService.phoneinfoUpdate(phoneInfo);
    }

    @GetMapping("/moveIndex")
    @UnInterception
    public R moveIndex(){
        Map<Object, Object> map = phoneInfoService.moveIndex();
        return  R.ok().data("data",map);
    }


    @GetMapping("/findSpecsByPhoneId/{phoneId}")
    @UnInterception
    public R findSpecsByPhoneId(@PathVariable Integer phoneId){
        Map<String, Object> data =  phoneInfoService.findSpecsByPhoneId(phoneId);

        return R.ok().data("data",data);
    }

    @GetMapping("/findByCategoryType/{type}")
    @UnInterception
    public R findByCategoryType(@PathVariable Integer type){
        List<PhoneinfoVo> phones = phoneInfoService.findByCategoryType(type);
        return  R.ok().data("data",phones);
    }

}
